package com.aliyun.messagemgt.application.service.Impl;

import com.aliyun.messagemgt.application.service.BaseTenantService;
import com.aliyun.messagemgt.domain.repository.IBaseTenantRepository;
import com.aliyun.messagemgt.dto.base.BaseTenantDTO;
import com.aliyun.messagemgt.entities.BaseTenant;
import com.aliyun.messagemgt.repository.mappers.BaseTenantMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class BaseTenantServiceImpl implements BaseTenantService {

    @Autowired
    private BaseTenantMapper baseTenantMapper;

    @Autowired
    private IBaseTenantRepository baseTenantRepository;

    @Override
    public BaseTenantDTO getByTenantCode(String tenantCode) {
        return baseTenantRepository.getByTenantCode(tenantCode);
    }

    @Override
    public BaseTenant selectByTenantCode(String tenantCode) {
        return baseTenantMapper.selectByTenantCode(tenantCode);
    }

    @Override
    public int updateByTenantCode(BaseTenant record) {
        return baseTenantMapper.updateByTenantCode(record);
    }

    @Override
    public String updateKeyCode(String tenantCode) {
        BaseTenant baseTenant = baseTenantMapper.selectByTenantCode(tenantCode);
        String keyName = UUID.randomUUID().toString().replaceAll("-", "");
        baseTenant.setKeyName(keyName);
        baseTenantMapper.updateByTenantCode(baseTenant);
        return keyName;
    }


}
